
require 'socket'
require 'readline'

if ARGV.length != 2
  STDERR.puts "usage: cncsh host port"
  exit
end

server = ARGV.shift
port = ARGV.shift.to_i

sock = TCPSocket.open(server, port)

puts "connect to %s:%d" % [server, port]


while command = Readline.readline("%s:%d> "%[server, port], true)
  break if command == 'quit' or command == 'exit'
  print "command: ", command, "\n"
  sock.puts command
  result = sock.gets
  print "result:  ", result, "\n"
end
